package xyz.caijiwang.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.caijiwang.entity.Best;
import xyz.caijiwang.mapper.BestMapper;
import xyz.caijiwang.service.BestService;

@Service
public class BestServiceImpl implements BestService {

    @Autowired
    BestMapper bestMapper;

    @Override
    public int getBestCountWithArticleid(Integer articleid) {
        return bestMapper.getBestCountWithArticleid(articleid);
    }

    @Override
    public Boolean checkWeatherIsSelected(Integer userid, Integer articleid) {
        Best best = bestMapper.checkWeatherIsSelected(userid, articleid);
        if (best == null) {
            return false;
        }
        return true;
    }

    @Override
    public void giveThumbsUp(Integer articleid, Integer userid) {
        Best best = new Best();
        best.setArticleid(articleid);
        best.setUserid(userid);
        bestMapper.insert(best);
    }

    @Override
    public void abolishGiveThumbsUp(Integer articleid, Integer userid) {
        bestMapper.deleteByUserAndArticle(userid, articleid);
    }

}
